import { UserLogin } from '@/api/user'

// 用户状态
export default {
  namespaced: true,
  state: () => {
    return {
      profile: {
        id: '',
        nickname: 'wx',
        token: ''
      }
    }
  },
  mutations: {
    btnId (state, id) {
      state.profile.id = id
    },
    // 保存登录用户数据
    setProfile (state, newProfile) {
      // console.log(20, newProfile)
      state.profile = newProfile
    },
    // 退出清空用户数据
    clearProfile (state) {
      state.profile = {
        id: '',
        nickname: '',
        avatar: '',
        token: '',
        mobile: ''
      }
    }
  },
  actions: {
    async login (store, form) {
      const { result } = await UserLogin(form)
      store.commit('setProfile', result)
    }
  }
}
